package com.redhat.auth.web.account;

import java.util.List;

import org.hibernate.Hibernate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dayatang.domain.InstanceFactory;
import com.dayatang.querychannel.service.QueryChannelService;
import com.redhat.auth.application.AccountApplication;
import com.redhat.auth.domain.Account;
import com.redhat.auth.domain.FunctionEntityType;
import com.redhat.redwork.widget.grid.AbstractGridModel;
import com.redhat.redwork.widget.grid.Order;

@Component
@Transactional
public class AccountGridModel extends AbstractGridModel<Account, Account> {

	private long count;
	@Autowired
	private AccountApplication accountApplication;

	public AccountApplication getAccountApplication() {
		return accountApplication;
	}

	public void setAccountApplication(AccountApplication accountApplication) {
		this.accountApplication = accountApplication;
	}

	@Override
	public List<Account> list(Account search, int page, int pageSize,
			Order order) {
		List<Account> accounts = accountApplication.listAcounts(search, page,
				pageSize);
		setCount(accounts == null ? 0 : accounts.size());
		return accounts;
	}

	@Override
	public Long count(Account search) {
		return count;
	}

	@Override
	public Account getCriteriaObject() {
		return new Account();
	}

	public long getCount() {
		return count;
	}

	public void setCount(long count) {
		this.count = count;
	}

}
